package com.itheima.d9_bufferedstream;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;

/**`
 * 缓冲字节输入流和缓冲字节输出流完成复制操作    用到装修设计模式！！！
 */
public class CopyDemo1 {
    public static void main(String[] args) {
        try(
                //1.创建对象
        FileInputStream fis = new FileInputStream("day06-file-io\\src\\a.txt");
        FileOutputStream fos = new FileOutputStream("day06-file-io\\src\\a_buffered.txt");//2.创建缓冲流 把fis 和 fos 装进去       //装修设计模式
                BufferedInputStream bis = new BufferedInputStream(fis);
                BufferedOutputStream bos = new BufferedOutputStream(fos);

        ){

            //3.copy
            byte[] buffer = new byte[1024];
            int len;
            while((len = bis.read(buffer)) != -1){
                bos.write(buffer, 0, len);
            }
            System.out.println("复制完毕！");
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}
